package com.bcxj.servicedriveruser.servcie;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bcxj.internalcommon.dto.ResponseResult;
import com.bcxj.internalcommon.entity.DriverUserWorkStatus;
import com.bcxj.servicedriveruser.mapper.DriverUserWorkStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * ClassName: DriverUserWorkStatusService
 * Package: com.bcxj.servicedriveruser.servcie
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/10/24 22:35
 * @Version 1.0
 * @Since 1.0
 */
@Service
public class DriverUserWorkStatusService {

    @Autowired
    private DriverUserWorkStatusMapper driverUserWorkStatusMapper;

    public ResponseResult updateWorkStatus(Long driverId, Integer status) {
        LambdaQueryWrapper<DriverUserWorkStatus> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DriverUserWorkStatus::getDriverId, driverId);
        DriverUserWorkStatus driverUserWorkStatus = driverUserWorkStatusMapper.selectOne(queryWrapper);

        // 下面这种情况一般不会出现，因为司机注册的时候会初始化状态
        if(driverUserWorkStatus == null) {
            return ResponseResult.fail("司机不存在");
        }

        driverUserWorkStatus.setWorkStatus(status);
        driverUserWorkStatusMapper.updateById(driverUserWorkStatus);
        return ResponseResult.success();
    }

}
